//
//  NSDictionary+Property.m
//  MaiMaiGo
//
//  Created by 孙鹏飞 on 2017/3/30.
//  Copyright © 2017年 qian. All rights reserved.
//  能够根据字典快速生成属性

#import "NSDictionary+Property.h"

@implementation NSDictionary (Property)

// isKindOfClass:可以用来判断是否是当前类或者子类
// 可以生成属性代码 => 根据当前字典中的key
- (void)createPropertyCode
{
    NSMutableString * codes = [NSMutableString string];
    // 遍历字典
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull value, BOOL * _Nonnull stop) {
        
        NSString * code; // 用字符串保存单条属性
        
        if ([value isKindOfClass:[NSString class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",key];
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",key];
        } else if ([value isKindOfClass:[NSNumber class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) NSInteger %@;",key];
        } else if ([value isKindOfClass:[NSArray class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",key];
        } else if ([value isKindOfClass:[NSDictionary class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",key];
        }
        
        [codes appendFormat:@"\n%@\n",code];
        
    }];
    
    NSLog(@"%@",codes);
}

@end
